package ruru.client;

import com.google.gwt.user.client.Element;

public class JSNI {
	/**
	 * Gets the height of the entire window's contents.
	 * @return
	 */
	public static native int getContentHeight() /*-{
		return $doc.body.clientHeight;
	}-*/;
	
	/**
	 * Gets the width of the entire window's contents.
	 * @return
	 */
	public static native int getContentWidth() /*-{
		return $doc.body.clientWidth;
	}-*/;
	
	
	public static native void disableSelection(Element element) /*-{
	    element.onselectstart = function() {
	        return false;
	    };
	    element.unselectable = "on";
	    element.style.MozUserSelect = "none";
	}-*/;
	
	/**
	 * The default GWT getClientHeight returns the total document height instead of the browser
	 * window's height.
	 * 
	 * @return
	 */
	public static native int getBrowserWindowHeight() /*-{
		var myHeight = 0;
			if( typeof( $wnd.innerWidth ) == 'number' ) {
		    // not-IE
		    myHeight = $wnd.innerHeight;
		  } else if( $doc.documentElement && ( $doc.documentElement.clientWidth || $doc.documentElement.clientHeight ) ) {
		    //IE 6+ in 'standards compliant mode'
		    myHeight = $doc.documentElement.clientHeight;
		  } else if( $doc.body && ( $doc.body.clientWidth || $doc.body.clientHeight ) ) {
		    //IE 4 compatible
		    myHeight = $doc.body.clientHeight;
		  }
		  
		  return myHeight;
	}-*/	;
	
	/**
	 * The default GWT getClientWidth works the same except in IE.
	 * 
	 * @return
	 */
	public static native int getBrowserWindowWidth() /*-{
	  var myWidth = 0;
	  if( typeof( $wnd.innerWidth ) == 'number' ) {
	    // not-IE
	    myWidth = $wnd.innerWidth;
	  } else if( $doc.documentElement && ( $doc.documentElement.clientWidth || $doc.documentElement.clientHeight ) ) {
	    //IE 6+ in 'standards compliant mode'
	    myWidth = $doc.documentElement.clientWidth;
	  } else if( $doc.body && ( $doc.body.clientWidth || $doc.body.clientHeight ) ) {
	    //IE 4 compatible
	    myWidth = $doc.body.clientWidth;
	  }
	  
	  return myWidth;
	}-*/;
	
	/**
	 * Found in You can find it in 'gwt-user.jar/com/google/gwt/user/UserAgent.gwt.xml'. Can't figure
	 * out how to call it though. Apparently it's set as a property somewhere.
	 */
	public static native String getBrowser() /*-{
		var ua = navigator.userAgent.toLowerCase();
		return ua;
	}-*/;
}